<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜数字游戏</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f4f4f9;
        }

        .game-container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        input {
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        button {
            padding: 10px 20px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        #message {
            margin-top: 20px;
            font-size: 18px;
        }
    </style>
</head>

<body>
    <div class="game-container">
        <h2>猜数字游戏</h2>
        <p>我已经想好了一个 1 到 100 之间的数字，你可以开始猜啦！</p>
        <input type="number" id="guess" placeholder="输入你的猜测">
        <button id="submit">提交猜测</button>
        <div id="message"></div>
    </div>
    <script>
        const secretNumber = Math.floor(Math.random() * 100) + 1;
        const guessInput = document.getElementById('guess');
        const submitButton = document.getElementById('submit');
        const messageElement = document.getElementById('message');

        submitButton.addEventListener('click', function () {
            const userGuess = parseInt(guessInput.value);
            if (isNaN(userGuess)) {
                messageElement.textContent = '请输入一个有效的数字！';
            } else if (userGuess < secretNumber) {
                messageElement.textContent = '猜小了，再试试！';
            } else if (userGuess > secretNumber) {
                messageElement.textContent = '猜大了，再试试！';
            } else {
                messageElement.textContent = '恭喜你，猜对啦！';
                submitButton.disabled = true;
                guessInput.disabled = true;
            }
        });
    </script>
</body>

</html>
    